{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import autogen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "config_list = autogen.config_list_openai_aoai()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "llm_config = {\n",
    "    \"seed\": 42,  # seed for caching and reproducibility\n",
    "    \"config_list\": config_list,  # a list of OpenAI API configurations\n",
    "    \"temperature\": 0,  # temperature for sampling\n",
    "    \"use_cache\": True,  # whether to use cache\n",
    "}\n",
    "# create an AssistantAgent named \"assistant\"\n",
    "assistant = autogen.AssistantAgent(\n",
    "    name=\"assistant\",\n",
    "    llm_config= llm_config,\n",
    ")\n",
    "# create a UserProxyAgent instance named \"user_proxy\"\n",
    "user_proxy = autogen.UserProxyAgent(\n",
    "    name=\"user_proxy\",\n",
    "    human_input_mode=\"NEVER\",\n",
    "    llm_config= llm_config,\n",
    "    max_consecutive_auto_reply=10,\n",
    "    is_termination_msg=lambda x: x.get(\"content\", \"\").rstrip().endswith(\"TERMINATE\"),\n",
    "    code_execution_config={\n",
    "        \"work_dir\": \"coding\",\n",
    "        \"use_docker\": False,  # set to True or image name like \"python:3\" to use docker\n",
    "    },\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# the assistant receives a message from the user_proxy, which contains the task description\n",
    "user_proxy.initiate_chat(\n",
    "    assistant,\n",
    "    message=\"\"\"What date is today? Compare the year-to-date gain for META and TESLA.\"\"\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "chat_messages = user_proxy.chat_messages[assistant]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'content': 'First, let\\'s get the current date using Python. \\n\\n```python\\n# python code\\nfrom datetime import date\\n\\n# Get today\\'s date\\ntoday = date.today()\\n\\nprint(\"Today\\'s date:\", today)\\n```\\n\\nNext, we need to fetch the stock prices for META (Facebook) and TESLA for the current year. We can use the `yfinance` library in Python to fetch this data. If it\\'s not installed, you can install it using pip:\\n\\n```shell\\n# shell script\\npip install yfinance\\n```\\n\\nAfter installing `yfinance`, we can fetch the stock prices:\\n\\n```python\\n# python code\\nimport yfinance as yf\\n\\n# Get data for the current year\\nstart_date = f\"{today.year}-01-01\"\\nend_date = str(today)\\n\\n# Get data for META (Facebook)\\nmeta_data = yf.download(\\'FB\\', start=start_date, end=end_date)\\n\\n# Get data for TESLA\\ntesla_data = yf.download(\\'TSLA\\', start=start_date, end=end_date)\\n\\n# Calculate the year-to-date gain for each stock\\nmeta_gain = ((meta_data[\\'Close\\'][-1] - meta_data[\\'Close\\'][0]) / meta_data[\\'Close\\'][0]) * 100\\ntesla_gain = ((tesla_data[\\'Close\\'][-1] - tesla_data[\\'Close\\'][0]) / tesla_data[\\'Close\\'][0]) * 100\\n\\nprint(f\"Year-to-date gain for META (Facebook): {meta_gain}%\")\\nprint(f\"Year-to-date gain for TESLA: {tesla_gain}%\")\\n```\\n\\nThis code will print the year-to-date gain for both META (Facebook) and TESLA.',\n",
       " 'role': 'user'}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chat_messages[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
